<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改用户订阅记录')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-userSubRecord-edit" th:object="${userSubRecord}">
            <input name="id" th:field="*{id}" type="hidden">
            <input name="userId" th:field="*{userId}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">用户标识：</label>
                <div class="col-sm-8">
                    <input name="userIdentify" th:field="*{userIdentify}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">设备标识：</label>
                <div class="col-sm-8">
                    <input name="deviceIdentify" th:field="*{deviceIdentify}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">应用：</label>
                <div class="col-sm-8">
                    <select name="productId" id="productId" class="form-control"  onchange="selectGoodType()">
                        <option value="">请选择应用</option>
                        <option th:each="product:${productList}" th:text="${product.name}" th:value="${product.id}" th:selected="${userSubRecord.productId eq product.id}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">服务名称：</label>
                <div class="col-sm-8">
                    <select name="goodsTypeId" id="goodsTypeId" class="form-control">
                        <option value="">请选择服务</option>
                        <option th:each="goodsType:${goodsTypeList}" th:text="${goodsType.name}" th:value="${goodsType.id}" th:selected="${userSubRecord.goodsTypeId eq goodsType.id}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">状态：</label>
                <div class="col-sm-8">
                    <select name="status" class="form-control">
                        <option th:text="有效" th:value="1" th:selected="*{status eq 1}"></option>
                        <option th:text="失效" th:value="0" th:selected="*{status eq 0}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">有效开始时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="effictStartTime" th:value="${#dates.format(userSubRecord.effictStartTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">有效截止时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="effictEndTime" th:value="${#dates.format(userSubRecord.effictEndTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">转写时间（秒）：</label>
                <div class="col-sm-8">
                    <input placeholder="单位为秒，数字自定义，只支持整数" name="effictTransferTime" th:field="*{effictTransferTime}" class="form-control" type="number">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "product/userSubRecord";
        $("#form-userSubRecord-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/saveOrUpdate", $('#form-userSubRecord-edit').serialize());
            }
        }

        function selectGoodType() {
            var productId = $("#productId").val();
            $.ajax({
                type: "GET",
                url: prefix + "/addChangeType?productId="+productId,
                cache: false,
                dataType: 'json',
                success: function(result) {
                    if (result) {
                        var html = "<option value=''>请选择服务</option>";
                        for (var i = 0; i < result.length; i++) {
                            html += "<option value='" + result[i].id + "'>" + result[i].name + "</option>"
                        }
                        $('#goodsTypeId').html(html);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("失败。");
                }
            });
        }

        $("input[name='effictStartTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='effictEndTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>